package com.loveyukari.service;

import com.loveyukari.utils.HttpUtils;
import net.sf.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.HashMap;

@Service
public class BaiduMapService {

    private Logger logger = LoggerFactory.getLogger(BaiduMapService.class);

    private String ak = "ZzrAV10SG5VM7pKjUieTioUzUOUZKhkK";

    private String getIpInfoUrl = "https://api.map.baidu.com/location/ip";



    public JSONObject getIpInfo(String ip){
        HashMap<String, Object> params = new HashMap<>();
        params.put("ip",ip);
        params.put("ak",ak);
        params.put("coor","bd09ll");
        try {
            String result = HttpUtils.sendGet(getIpInfoUrl, params);
            return JSONObject.fromObject(result);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
        }
        return null;
    }





}
